﻿using FastCloud.Base.Config;
using FastCloud.Base.Desgin;
using FastCloud.ORG.Entity;
using FastIOC.Attribute;
using FastUtil.Convert;
using FastUtil.Data;
using System;
using System.Collections.Generic;
using System.Text;

namespace FastCloud.ORG.DB
{
    public class DB_Tenant : BaseDBML<Frame_Tenant>
    {

        public override void Insert(Frame_Tenant Entity)
        {
            if (string.IsNullOrEmpty(Entity.TenantID))
            {
                Entity.TenantID = GenerateUtil.GenerateRowGuid();
            }
            Entity.AddDate = DateTime.Now;
            base.Insert(Entity);
        }

        public bool ExistTenant(string TenantName)
        {
            string sql = string.Format("select count(1) from Frame_Tenant where TenantName='{0}'", TenantName);
            return CommonDao.ExecuteToInt(sql) > 0 ? true : false;
        }

        public bool ExistTenant(string TenantID,string TenantName)
        {
            string sql = string.Format("select count(1) from Frame_Tenant where TenantName='{0}' and TenantID!='{1}'", TenantName, TenantID);
            return CommonDao.ExecuteToInt(sql) > 0 ? true : false;
        }
    }
}
